<!DOCTYPE html>
<html>
<head>
    
    <include file="Common/head"/>
    
    <link href="__CSS__/plugins/iCheck/custom.css" rel="stylesheet">
    <script src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>

</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    
    <!-- Panel Other -->
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>{$title}</h5>
        </div>
        <div class="ibox-content">
            <div class="row row-lg">
                <div class="col-sm-12">
                    <include file="Common/alert"/>
                    <div class="clearfix" style="width:100%;">
                        <div class="bars pull-left">
                            <div class="btn-group hidden-xs" id="exampleTableEventsToolbar" role="group">
                                <button type="button" class="btn btn-outline btn-default" href="{:U('Article/index',['category_id'=>I('get.category_id')])}" style="padding-bottom: 8px;padding-top: 8px;">
                                    <i class="glyphicon glyphicon-chevron-left" aria-hidden="true"></i>
                                </button>
                                <button type="button" class="btn btn-outline btn-default" href="{:U('Article/add',['category_id'=>I('get.category_id')])}" style="padding-bottom: 8px;padding-top: 8px;">
                                    <i class="glyphicon glyphicon-plus" aria-hidden="true"></i>
                                </button>
                                <button class="btn btn-default btn-outline" type="button" name="refresh" title="刷新" href="__SELF__" style="padding-bottom: 8px;padding-top: 8px;">
                                    <i class="glyphicon glyphicon-repeat"></i>
                                </button>
                            </div>
                        </div>
                    </div>
    
                    <form method="post" action="{:U('Article/update')}" class="form-horizontal">
    
                        <volist name=":parse_config_attr($model['field_group'])" id="group">
                            <volist name="fields[$key]" id="field">
                                <if condition="$field['is_show'] == 1 || $field['is_show'] == 3">
                                    <div class="hr-line-dashed"></div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">{$field['title']}</label>
                                        <div class="col-sm-10">
                                            <switch name="field.type">
                                                <case value="num">
                                                    <input name="{$field.name}" type="number" class="form-control" value="{$info[$field['name']]|default=''}" style="width: 30%;">
                                                </case>
                                                <case value="number">
                                                    <input name="{$field.name}" type="number" class="form-control" value="{$info[$field['name']]|default=''}" style="width: 30%;">
                                                </case>
                                                <case value="string">
                                                    <input name="{$field.name}" type="text" class="form-control" value="{$info[$field['name']]|default=''}">
                                                </case>
                                                <case value="textarea">
                                                    <textarea name="{$field.name}" class="form-control" rows="4">{$data[$field['name']]|default=''}</textarea>
                                                </case>
                                                <case value="date">
                                                    <input type="text" name="{$field.name}" class="text date" value="{$data[$field['name']]|date='Y-m-d',###}" placeholder="请选择日期" />
                                                </case>
                                                <case value="datetime">
                                                    <input type="datetime-local" name="datetime-{$field.name}" class="text time" value="{:time_format()}" />
                                                    <input type="hidden" name="{$field.name}" value="{$info[$field['name']]}"/>
                                                    <script>
                                                        $(function(){
                                                            $("input[name='datetime-{$field.name}']").trigger('change');
                                                            $("input[name='datetime-{$field.name}']").on('change', function(){
                                                                console.log($(this).val());
                                                                var local = $(this).val();// 2017-05-02T08:33
                                                                console.log(local.substring(0,4));
                                                                console.log(local.substring(5,7)-1);
                                                                var date = new Date();
                                                                date.setFullYear(local.substring(0,4));
                                                                date.setMonth(local.substring(5,7)-1);
                                                                date.setDate(local.substring(8,10));
                                                                date.setHours(local.substring(11,13));
                                                                date.setMinutes(local.substring(14,16));
                                                                var str = Date.parse(date)/1000;
                                                                console.log(str);
                                                                $("input[name='{$field.name}']").val(str);
                                                            });
                                                        });
                                                    </script>
                                                </case>
                                                <case value="bool">
                                                    <select name="{$field.name}">
                                                        <volist name=":parse_field_attr($field['extra'])" id="vo">
                                                            <option value="{$key}" <eq name="data[$field['name']]" value="$key">selected</eq>>{$vo}</option>
                                                        </volist>
                                                    </select>
                                                </case>
                                                <case value="select">
                                                    <select name="{$field.name}">
                                                        <volist name=":parse_field_attr($field['extra'])" id="vo">
                                                            <option value="{$key}" <eq name="data[$field['name']]" value="$key">selected</eq>>{$vo}</option>
                                                        </volist>
                                                    </select>
                                                </case>
                                                <case value="radio">
                                                    <volist name=":parse_field_attr($field['extra'])" id="vo">
                                                        <label class="radio" style="padding-left: 20px; cursor: pointer;">
                                                            <input type="radio" value="{$key}" name="{$field.name}" <eq name="data[$field['name']]" value="$key">checked="checked"</eq> style="margin-top: 2px;">{$vo}
                                                        </label>
                                                    </volist>
                                                </case>
                                                <case value="checkbox">
                                                    <volist name=":parse_field_attr($field['extra'])" id="vo">
                                                        <label class="checkbox-inline">
                                                            <input type="checkbox" value="{$key}" name="{$field.name}[]" <if condition="check_document_position($info[$field['name']],$key)">checked="checked"</if> style="margin-top:0;">{$vo}
                                                        </label>
                                                    </volist>
                                                </case>
                                                <case value="editor">
                                                    <switch name="ADMIN_EDITOR">
                                                        <case value="ueditor">
                                                            <script id="{$field.name}" name="{$field.name}" type="text/plain" style="width:100%;height:240px;">{$info[$field['name']]}</script>
                                                            <script type="text/javascript" charset="utf-8" src="__STATIC__/ueditor/ueditor.config.js"></script>
                                                            <script type="text/javascript" charset="utf-8" src="__STATIC__/ueditor/ueditor.all.min.js"> </script>
                                                            <!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
                                                            <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
                                                            <script type="text/javascript" charset="utf-8" src="__STATIC__/ueditor/lang/zh-cn/zh-cn.js"></script>
            
                                                            <script type="text/javascript">
                                                                //实例化编辑器
                                                                //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
                                                                var ue = UE.getEditor('{$field.name}',{
                                                                    
                                                                });
                                                            </script>
        
                                                        </case>
                                                        <case value="umeditor">
                                                            <textarea id="{$field.name}" name="{$field.name}" style="width:100%;height:240px;">{$info[$field['name']]}</textarea>
                                                            <!--:hook('adminArticleEdit', array('name'=>$field['name'],'value'=>$data[$field['name']]))}-->
                                                            <link href="__STATIC__/umeditor/themes/default/css/umeditor.css" type="text/css" rel="stylesheet">
                                                            <script type="text/javascript" src="__STATIC__/umeditor/third-party/template.min.js"></script>
                                                            <!-- 配置文件 -->
                                                            <script type="text/javascript" src="__STATIC__/umeditor/umeditor.config.js"></script>
                                                            <!-- 编辑器源码文件 -->
                                                            <script type="text/javascript" src="__STATIC__/umeditor/umeditor.min.js"></script>
                                                            <!--<script type="text/javascript" src="__STATIC__/umeditor/lang/zh-cn/zh-cn.js"></script>-->
                                                            <!-- 实例化编辑器 -->
                                                            <script type="text/javascript">
                                                                //实例化编辑器
                                                                var um = UM.getEditor('{$field.name}',{
                                                                    imageUrl:"{:U('File/editor')}",
                                                                    imagePath:""
                                                                });
                                                            </script>
                                                        </case>
                                                        <default/>
                                                        <textarea id="{$field.name}" name="{$field.name}" style="width:100%;height:240px;">{$info[$field['name']]}</textarea>
                                                        <!--:hook('adminArticleEdit', array('name'=>$field['name'],'value'=>$data[$field['name']]))}-->
                                                        <link href="__STATIC__/umeditor/themes/default/css/umeditor.css" type="text/css" rel="stylesheet">
                                                        <script type="text/javascript" src="__STATIC__/umeditor/third-party/template.min.js"></script>
                                                        <!-- 配置文件 -->
                                                        <script type="text/javascript" src="__STATIC__/umeditor/umeditor.config.js"></script>
                                                        <!-- 编辑器源码文件 -->
                                                        <script type="text/javascript" src="__STATIC__/umeditor/umeditor.min.js"></script>
                                                        <!--<script type="text/javascript" src="__STATIC__/umeditor/lang/zh-cn/zh-cn.js"></script>-->
                                                        <!-- 实例化编辑器 -->
                                                        <script type="text/javascript">
                                                            //实例化编辑器
                                                            var um = UM.getEditor('{$field.name}',{
                                                                imageUrl:"{:U('File/editor')}",
                                                                imagePath:""
                                                            });
                                                        </script>
                                                    </switch>
                                                </case>
                                                <case value="picture">
                                                    <div class="controls">
                                                        <input type="file" id="upload_picture_{$field.name}">
                                                        <input type="hidden" name="{$field.name}" id="cover_id_{$field.name}" value="{$info[$field['name']]}"/>
                                                        <div class="upload-img-box">
                                                            <notempty name="info[$field['name']]">
                                                                <div class="upload-pre-item"><img src="{$info[$field['name']]|get_cover='path'}"/></div>
                                                            </notempty>
                                                        </div>
                                                    </div>
                                                    <style>
                                                        .upload-button{
                                                            background: #1ab394;
                                                            color: white;
                                                            text-align: center;
                                                        }
                                                    </style>
                                                    <script type="text/javascript">
                                                        //上传图片
                                                        /* 初始化上传插件 */
                                                        $("#upload_picture_{$field.name}").uploadify({
                                                            'buttonClass'   :"upload-button",
                                                            "height"          : 30,
                                                            "swf"             : "__STATIC__/uploadify/uploadify.swf",
                                                            "fileObjName"     : "download",
                                                            "buttonText"      : "上传图片",
                                                            "uploader"        : "{:U('File/uploadPicture',array('session_id'=>session_id()))}",
                                                            "width"           : 120,
                                                            'removeTimeout'	  : 1,
                                                            'fileTypeExts'	  : '*.jpg; *.png; *.gif;',
                                                            "onUploadSuccess" : uploadPicture{$field.name},
                                                        'onFallback' : function() {
                                                            alert('未检测到兼容版本的Flash.');
                                                        }
                                                        });
                                                        function uploadPicture{$field.name}(file, data){
                                                            var data = $.parseJSON(data);
                                                            var src = '';
                                                            if(data.status){
                                                                $("#cover_id_{$field.name}").val(data.id);
                                                                src = data.url || '__ROOT__' + data.path;
                                                                
                                                                $("#cover_id_{$field.name}").parent().find('.upload-img-box').html(
                                                                    '<div class="upload-pre-item"><img src="' + src + '"/></div>'
                                                                );
                                                            } else {
                                                                updateAlert(data.info);
                                                                setTimeout(function(){
                                                                    $('#top-alert').find('button').click();
                                                                    $(that).removeClass('disabled').prop('disabled',false);
                                                                },1500);
                                                            }
                                                        }
                                                    </script>
                                                </case>
                                                <case value="pictures">
                                                    <div class="controls">
                                                        <input type="file" id="upload_picture_{$field.name}">
                                                        <input type="hidden" name="{$field.name}" id="cover_id_{$field.name}" value="{$info[$field['name']]}"/>
                                                        <div class="upload-img-box">
                                                            <notempty name="info[$field['name']]">
                                                                <div class="upload-pre-item"><img src="{$info[$field['name']]|get_cover='path'}"/></div>
                                                            </notempty>
                                                        </div>
                                                    </div>
                                                    <style>
                                                        .upload-button{
                                                            background: #1ab394;
                                                            color: white;
                                                            text-align: center;
                                                        }
                                                    </style>
                                                    <script type="text/javascript">
                                                        //上传图片
                                                        /* 初始化上传插件 */
                                                        $("#upload_picture_{$field.name}").uploadify({
                                                            'buttonClass'   :"upload-button",
                                                            "height"          : 30,
                                                            "swf"             : "__STATIC__/uploadify/uploadify.swf",
                                                            "fileObjName"     : "download",
                                                            "buttonText"      : "上传图片",
                                                            "uploader"        : "{:U('File/uploadPicture',array('session_id'=>session_id()))}",
                                                            "width"           : 120,
                                                            'removeTimeout'	  : 1,
                                                            'fileTypeExts'	  : '*.jpg; *.png; *.gif;',
                                                            "onUploadSuccess" : uploadPicture{$field.name},
                                                        'onFallback' : function() {
                                                            alert('未检测到兼容版本的Flash.');
                                                        }
                                                        });
                                                        function uploadPicture{$field.name}(file, data){
                                                            var data = $.parseJSON(data);
                                                            var src = '';
                                                            if(data.status){
                                                                $("#cover_id_{$field.name}").val(data.id);
                                                                src = data.url || '__ROOT__' + data.path;

                                                                $("#cover_id_{$field.name}").parent().find('.upload-img-box').html(
                                                                    '<div class="upload-pre-item"><img src="' + src + '"/></div>'
                                                                );
                                                            } else {
                                                                updateAlert(data.info);
                                                                setTimeout(function(){
                                                                    $('#top-alert').find('button').click();
                                                                    $(that).removeClass('disabled').prop('disabled',false);
                                                                },1500);
                                                            }
                                                        }
                                                    </script>
                                                </case>
                                                <case value="file">
                                                    <div class="controls">
                                                        <input type="file" id="upload_file_{$field.name}">
                                                        <input type="hidden" name="{$field.name}" value="{:think_encrypt(json_encode(get_table_field($data[$field['name']],'id','','File')))}"/>
                                                        <div class="upload-img-box">
                                                            <present name="data[$field['name']]">
                                                                <div class="upload-pre-file"><span class="upload_icon_all"></span>{$data[$field['name']]|get_table_field=###,'id','name','File'}</div>
                                                            </present>
                                                        </div>
                                                    </div>
                                                    <script type="text/javascript">
                                                        //上传图片
                                                        /* 初始化上传插件 */
                                                        $("#upload_file_{$field.name}").uploadify({
                                                            "height"          : 30,
                                                            "swf"             : "__STATIC__/uploadify/uploadify.swf",
                                                            "fileObjName"     : "download",
                                                            "buttonText"      : "上传附件",
                                                            "uploader"        : "{:U('File/upload',array('session_id'=>session_id()))}",
                                                            "width"           : 120,
                                                            'removeTimeout'	  : 1,
                                                            "onUploadSuccess" : uploadFile{$field.name},
                                                        'onFallback' : function() {
                                                            alert('未检测到兼容版本的Flash.');
                                                        }
                                                        });
                                                        function uploadFile{$field.name}(file, data){
                                                            var data = $.parseJSON(data);
                                                            if(data.status){
                                                                var name = "{$field.name}";
                                                                $("input[name="+name+"]").val(data.data);
                                                                $("input[name="+name+"]").parent().find('.upload-img-box').html(
                                                                    "<div class=\"upload-pre-file\"><span class=\"upload_icon_all\"></span>" + data.info + "</div>"
                                                                );
                                                            } else {
                                                                updateAlert(data.info);
                                                                setTimeout(function(){
                                                                    $('#top-alert').find('button').click();
                                                                    $(that).removeClass('disabled').prop('disabled',false);
                                                                },1500);
                                                            }
                                                        }
                                                    </script>
                                                </case>
                                                <default/>
                                                <input type="text" class="text input-large" name="{$field.name}" value="{$data[$field['name']]}">
                                            </switch>
                                            <notempty name="field['remark']"><span class="help-block m-b-none">{$field['remark']}</span></notempty>
                                        </div>
                                    </div>
                                </if>
                            </volist>
                        </volist>
    
                        <div class="hr-line-dashed"></div>
    
                        <input type="hidden" name="id" value="{$info.id|default=''}"/>
                        <input type="hidden" name="uid" value="{$info.id|default=session('user_auth.uid')}"/>
                        <input type="hidden" name="pid" value="{:I('pid',0)}"/>
                        <input type="hidden" name="model_id" value="{$info.model_id|default=''}"/>
                        <input type="hidden" name="group_id" value="{$info.group_id|default=''}"/>
                        <input type="hidden" name="category_id" value="{$info.category_id|default=''}">
    
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-2">
                                <button class="btn btn-primary" type="submit">保存内容</button>
                                <button class="btn btn-white" type="submit" onclick="window.history.go(-1);">取消</button>
                            </div>
                        </div>
        
                    </form>
                </div>
                
            </div>
        </div>
    </div>
    <!-- End Panel Other -->
</div>
<include file="Common/footer"/>
<script src="__JS__/content.min.js?v=1.0.0"></script>
<script src="__JS__/plugins/iCheck/icheck.min.js"></script>
<script src="__JS__/plugins/summernote/summernote.min.js"></script>
<script src="__JS__/plugins/summernote/summernote-zh-CN.js"></script>

<script>
    $(document).ready(function(){$(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green",})});
    $(document).ready(function(){$(".summernote").summernote({lang:"zh-CN"})});var edit=function(){$("#eg").addClass("no-padding");$(".click2edit").summernote({lang:"zh-CN",focus:true})};var save=function(){$("#eg").removeClass("no-padding");var aHTML=$(".click2edit").code();$(".click2edit").destroy()};
</script>
</body>
</html>
